import { SkillCareerMapPanel } from "./SkillCareerMapPanel";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Cache } from "../../../cache/Cache";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { SkillInfo } from "../../../model/SkillInfo";
import { SkillItem } from "../SkillItem";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { EffectManager } from "../../../manager/EffectManager";
import { GameController } from "../../../mvc/GameController";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
type int = number;
//class SkillCareerMapBasePanel
    
    export  class SkillCareerMapBasePanel extends SkillCareerMapPanel
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onSkillUILoadedHandler(): void
        {
            var loc3=null;
            if (this._skillMapMC && this._skillMapMC.parent) 
            {
                removeChild(this._skillMapMC);
            }
            this._skillMapMC = new (GlobalClass.getClass("skill_" + Cache.instance.role.roleInfo.career) as Class)();
            this._skillMapMC.mouseEnabled = false;
            addChild(this._skillMapMC);
            _clickIndex = 0;
            _skillItems.splice(0);
            var loc1=1;
            var loc2=this._skillMapMC["border" + loc1];
            while (loc2 != null) 
            {
                loc3 = _list[(loc1 - 1)];
                this.refreshSkill(loc3.position, loc3);
                ++loc1;
                loc2 = this._skillMapMC["border" + loc1];
            }
            initCallLater();
            if (_clickNext != -1) 
            {
                this.itemClick(_clickNext);
            }
            if (_lastUpdateInfo != null) 
            {
                this.updateSkill(_lastUpdateInfo);
            }
            return;
        }

        public /* override */ initSkill(arg1: Array<any>): void
        {
            super.initSkill(arg1);
            LoaderHelp.addResCallBack("skillUI.swf", this.onSkillUILoadedHandler);
            return;
        }

        protected /* override */ refreshSkill(arg1: int, arg2: SkillInfo): void
        {
            if (this._skillMapMC == null) 
            {
                return;
            }
            var loc1=_skillItems[arg1];
            if (!loc1) 
            {
                loc1 = new SkillItem();
                _skillItems[arg1] = loc1;
            }
            loc1.data = arg2;
            loc1.amount = arg2.tSkill.skillLevel;
            if (!loc1.parent) 
            {
                loc1.x = 3;
                loc1.y = 3;
                this._skillMapMC["border" + arg1].addChild(loc1);
            }
            if (arg2.learned) 
            {
                this.setSkillLearnableFilters(arg1, loc1, null, [FilterConst.skillItemFilter], null, null);
            }
            else if (arg2.learnedAble) 
            {
                this.setSkillLearnableFilters(arg1, loc1, null, [FilterConst.skillItemFilter], null, null);
            }
            else 
            {
                this.setSkillLearnableFilters(arg1, loc1, [FilterConst.colorFilter2], [FilterConst.colorFilter2, FilterConst.skillItemFilter], [FilterConst.colorFilter2], [FilterConst.colorFilter2]);
            }
            loc1.toolTipDataFunction = getToolTipData;
            return;
        }

        /* internal  */setSkillLearnableFilters(arg1: int, arg2: SkillItem, arg3: Array<any>, arg4: Array<any>, arg5: Array<any>, arg6: Array<any>): void
        {
            var loc2=null;
            var loc1=0;
            arg2.filters = arg3;
            if (_clickIndex != arg1) 
            {
                this._skillMapMC["border" + arg1].filters = arg5;
            }
            else 
            {
                this._skillMapMC["border" + arg1].filters = arg4;
            }
            while (loc1 < this._skillMapMC.numChildren) 
            {
                if ((loc2 = this._skillMapMC.getChildAt(loc1) as Object /* flash.display.MovieClip */) && loc2.name.split("_")[0] == "line" + arg1) 
                {
                    loc2.filters = arg6;
                }
                ++loc1;
            }
            return;
        }

        public /* override */ itemClick(arg1: int): void
        {
            super.itemClick(arg1);
            if (arg1 == _clickIndex) 
            {
                return;
            }
            if (!this._skillMapMC) 
            {
                _clickNext = arg1;
                return;
            }
            if (_clickIndex != 0) 
            {
                if (skillItems[_clickIndex].data.learned) 
                {
                    this._skillMapMC["border" + _clickIndex].filters = null;
                }
                else if (skillItems[_clickIndex].data.learnedAble) 
                {
                    this._skillMapMC["border" + _clickIndex].filters = null;
                }
                else 
                {
                    this._skillMapMC["border" + _clickIndex].filters = [FilterConst.colorFilter2];
                }
            }
            _clickIndex = arg1;
            if (skillItems[_clickIndex].data.learned) 
            {
                this._skillMapMC["border" + _clickIndex].filters = [FilterConst.skillItemFilter];
            }
            else if (skillItems[_clickIndex].data.learnedAble) 
            {
                this._skillMapMC["border" + _clickIndex].filters = [FilterConst.skillItemFilter];
            }
            else 
            {
                this._skillMapMC["border" + _clickIndex].filters = [FilterConst.colorFilter2, FilterConst.skillItemFilter];
            }
            return;
        }

        public /* override */ autoUseAble(arg1: SkillInfo): void
        {
            super.autoUseAble(arg1);
            var loc1=_skillItems[arg1.position];
            loc1.autoUseAble = arg1.autoUse;
            return;
        }

        public /* override */ updateSkill(arg1: SkillInfo): SkillInfo
        {
            var loc3=0;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            super.updateSkill(arg1);
            if (this._skillMapMC == null) 
            {
                _lastUpdateInfo = arg1;
                return null;
            }
            var loc1=_skillItems[arg1.position];
            this.refreshSkill(arg1.position, arg1);
            EffectManager.glowFilterUnReg(loc1);
            loc1.levelUpAble = false;
            if (Cache.instance.guide.guideSkillLearn && arg1.position == 1 && arg1.learned == true && arg1.skillLevel == 1) 
            {
                if (loc6 = GameController.shortcuts.getSkillPos(arg1.tSkill.skillId)) 
                {
                    loc7 = this._skillMapMC["border1"].localToGlobal(new Object /* flash.geom.Point */(loc1.x, loc1.y));
                    FlyToNavbarTool.flyToAnyPoint(loc1.bitmapdata, loc7, loc6, onFlyEnd);
                }
            }
            var loc2=this.guideLevelUp(Cache.instance.skill.skillLearnAble, false);
            var loc4=Cache.instance.skill.skillMaps.length;
            while (loc3 < loc4) 
            {
                if ((loc5 = Cache.instance.skill.skillMaps[loc3]).tSkill.preSkillId == arg1.tSkill.skillId) 
                {
                    this.refreshSkill(loc5.position, loc5);
                }
                ++loc3;
            }
            return loc2;
        }

        public /* override */ guideLevelUp(arg1: Array<any>, arg2: Boolean): SkillInfo
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc5=false;
            super.guideLevelUp(arg1, arg2);
            var loc2=arg1.length;
            var loc6=-1;
            while (loc1 < loc2) 
            {
                loc3 = arg1[loc1];
                if ((loc4 = _skillItems[loc3.position]) != null) 
                {
                    if (!loc5) 
                    {
                        loc5 = true;
                        this.itemClick(loc3.position);
                        if (!EffectManager.getGlowFilters(loc4)) 
                        {
                            EffectManager.glowFilterReg(loc4, [new Object /* flash.filters.GlowFilter */(65280, 1, 10, 10, 2)]);
                        }
                        loc6 = loc1;
                    }
                    loc4.levelUpAble = true;
                }
                ++loc1;
            }
            if (loc6 != -1) 
            {
                return arg1[loc6] as SkillInfo;
            }
            return null;
        }

        public /* override */ guideLevelUpClear(): void
        {
            var loc1=0;
            var loc3=null;
            super.guideLevelUpClear();
            var loc2=_skillItems.length;
            while (loc1 < loc2) 
            {
                loc3 = _skillItems[loc1];
                if (loc3 != null) 
                {
                    loc3.levelUpAble = false;
                    EffectManager.glowFilterUnReg(loc3);
                }
                ++loc1;
            }
            return;
        }

        protected /* var */_skillMapMC: Object /* flash.display.MovieClip */;
    }
